package com.bcmusic.point.controller;

import com.bcmusic.point.pojo.UserMbLog;
import com.bcmusic.point.service.UserMbLogService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/userMbLog")
@CrossOrigin
public class UserMbLogController {

    @Autowired
    private UserMbLogService userMbLogService;

    /***
     * UserMbLog分页条件搜索实现
     * @param userMbLog
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  UserMbLog userMbLog, @PathVariable  int page, @PathVariable  int size){
        //调用UserMbLogService实现分页条件查询UserMbLog
        PageInfo<UserMbLog> pageInfo = userMbLogService.findPage(userMbLog, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * UserMbLog分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用UserMbLogService实现分页查询UserMbLog
        PageInfo<UserMbLog> pageInfo = userMbLogService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param userMbLog
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<UserMbLog>> findList(@RequestBody(required = false)  UserMbLog userMbLog){
        //调用UserMbLogService实现条件查询UserMbLog
        List<UserMbLog> list = userMbLogService.findList(userMbLog);
        return new Result<List<UserMbLog>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用UserMbLogService实现根据主键删除
        userMbLogService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改UserMbLog数据
     * @param userMbLog
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  UserMbLog userMbLog,@PathVariable Long id){
        //设置主键值
        userMbLog.setMbLogId(id);
        //调用UserMbLogService实现修改UserMbLog
        userMbLogService.update(userMbLog);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增UserMbLog数据
     * @param userMbLog
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   UserMbLog userMbLog){
        //调用UserMbLogService实现添加UserMbLog
        userMbLogService.add(userMbLog);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询UserMbLog数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<UserMbLog> findById(@PathVariable Long id){
        //调用UserMbLogService实现根据主键查询UserMbLog
        UserMbLog userMbLog = userMbLogService.findById(id);
        return new Result<UserMbLog>(true,StatusCode.OK,"查询成功",userMbLog);
    }

    /***
     * 查询UserMbLog全部数据
     * @return
     */
    @GetMapping
    public Result<List<UserMbLog>> findAll(){
        //调用UserMbLogService实现查询所有UserMbLog
        List<UserMbLog> list = userMbLogService.findAll();
        return new Result<List<UserMbLog>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
